using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Galplay {
  public class GalScriptPack {
    public string Name { get; }
    public List<GalScene> Items { get; }
    public Dictionary<int, GalScene> SearchMap { get; }

    public GalScriptPack(string name, XmlReader xml) {
      Name = name;

      // 读取脚本
      var items = xml.Root.GetNodes("Command");

      Items = new List<GalScene>(items.Count);
      SearchMap = new Dictionary<int, GalScene>(items.Count);
      foreach (XmlNode item in items) {
        var scene = new GalScene(item);
        SearchMap[scene.EventID] = scene;
        Items.Add(scene);
      }
    }

    internal GalScene Get(int eventID) {
      // 尝试获取指定ID的场景
      if (SearchMap.TryGetValue(eventID, out GalScene scene)) {
        return scene;
      }

      // 未找到对应ID的场景
      Debuger.LogWarning($"未找到ID为 {eventID} 的Event.");
      return null;
    }
  }
}